package com.td.erhome.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.td.erhome.R;

/**
 * Created by admin on 2017/2/14.
 */

public class CostAreaAdapter extends RecyclerView.Adapter<CostAreaAdapter.MyViewHolder> {
    private Context mContext;
    private String[]  mData;
    private OnRecyclerViewItemClickListener mOnItemClickListener = null;

    public CostAreaAdapter(Context context, String[] data){
        this.mContext = context;
        mData = data;
    }



    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = View.inflate(mContext, R.layout.pop_more_item, null);
        MyViewHolder holder = new MyViewHolder(itemView);
        return holder;
    }

    @Override

    public void onBindViewHolder(final MyViewHolder holder, final int position) {
        holder.mTvItem.setText(mData[position]);

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //获取当前点击的位置
                mOnItemClickListener.onItemClick(mData[position]);
            }
        });

    }

    //define interface
    public static interface OnRecyclerViewItemClickListener {
        void onItemClick(String sn);
    }

    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }


    @Override
    public int getItemCount() {
        return mData.length;
    }
    class MyViewHolder extends RecyclerView.ViewHolder {

        private final TextView mTvItem;

        public MyViewHolder(View itemView) {
            super(itemView);
            mTvItem = (TextView) itemView.findViewById(R.id.tv_item);
        }
    }
}
